<template>
	<view class="help-container" @touchmove.stop.prevent="() => {}">

		<view class="subsection">
			<view class="item  " @click="changeType('lost')" :class="{'active': currentType==='lost' }">
				<view class="num">{{lostOrder.length}}</view>
				<view class="text">我的失物招领</view>
			</view>
			<view class="item  " @click="changeType('find')" :class="{'active': currentType==='find' }">
				<view class="num">{{findOrder.length}}</view>
				<view class="text">我的寻物启事</view>
			</view>


		</view>

		<view class="card-list" v-if="currentType=== 'lost'">
			<view class="order-card" v-for="(item,index) in lostOrder" :key="index">
				<lostGoods class="order-card" :lostInfo="item" @cancelPublish="getLostOrder"></lostGoods>
			</view>
			<emptyData v-if="!lostOrder.length" :tip="'暂无失物信息'"> </emptyData>
		</view>
		<view class="card-list" v-else>
			<view class="order-card" v-for="(item,index) in findOrder" :key="index">
				<lostGoods class="order-card" :lostInfo="item" @cancelPublish="getLostOrder"></lostGoods>
			</view>
			<emptyData v-if="!findOrder.length" :tip="'暂无寻物信息'"> </emptyData>
		</view>


	</view>
</template>

<script>
	import lostGoods from '../../components/lostGoods.vue'
	import emptyData from '../../components/emptyData.vue'
	export default {
		components: {
			lostGoods,
			emptyData
		},
		data() {
			return {
				currentType: 'lost',
				lostOrFindOrder: [],
				lostOrder: [],
				findOrder: []
			};
		},
		onLoad() {
			this.getLostOrder()
		},
		methods: {
			changeType(type) {
				this.currentType = type
			},
			tabChange(e) {

			},
			// 获取失物招领信息
			getLostOrder() {
				this.$http('get', 'api/public/lostAndFind/list', {
					success: (res) => {
						const userInfo = this.$store.getters.userInfo
						this.lostOrFindOrder = res.data
						this.lostOrder = this.lostOrFindOrder.filter(item =>
							item.lostOrderType === '0' && item.uid === userInfo.uid
						)
						this.findOrder = this.lostOrFindOrder.filter(item =>
							item.lostOrderType === '1' && item.uid === userInfo.uid
						)
					}
				})
			},
		}
	}

</script>

<style lang="scss">
	.help-container {
		height: 100vh;
		padding: 0 15px;
	}



	.subsection {
		box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
		border-radius: 8px;
		margin: 15px 0;
		background: #fff;
		height: 80px;
		display: flex;
		align-items: center;
		padding: 0 10px;

		.item {
			flex: 1;
			height: 60px;

			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;

			&.active {
				background: rgb(255, 255, 255);
				box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.2);
				border-radius: 8px;

				.text {
					font-weight: 700;
				}
			}

			.num {
				font-size: 18px;
				text-align: center;
				font-weight: 700;
			}

			.text {
				text-align: center;
				font-size: 12px;
				color: rgb(51, 51, 51);
				margin-top: 10px;
			}

			&:nth-child(1) {
				.num {
					color: rgb(254, 185, 58);
				}

			}

			&:nth-child(2) {
				.num {
					color: rgb(101, 132, 247);
				}

			}

			&:nth-child(3) {
				.num {
					color: rgb(245, 63, 63);
				}

			}
		}

	}

	.card-list {
		margin-top: 10px;
		height: calc(100% - 160px);
		overflow: auto;


		.order-card:not(:last-child) {
			margin-bottom: 10px;
		}
	}


	.find-help {
		padding-left: 10px;
		width: 90px;
		height: 38px;
		position: fixed;
		bottom: 80px;
		right: 0;
		color: #fff;
		display: flex;
		background: linear-gradient(135deg, #7676ee 0%, #b064fb 100%);
		box-shadow: 0px 2px 10px #8a70f2;
		border-radius: 20px 0px 0px 20px;
		align-items: center;
		font-size: 14px;

		img {
			margin-right: 8px;
		}
	}

</style>

